<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
$v=trim($_GET["v"]);
//$selectlist=array(15,17);
$selectlist=array();
if($v<>""){
    if(strpos($v,",")>0){
        $selectlist=explode(",",$v);
    }else{
        $selectlist[]=$v;        
    }
    
}

function listcategory($parentid=0){
         global $ezhand,$modellist;
         $total=$ezhand->count("category","parentid=".$parentid);
         $row=$ezhand->select_all("category",'*',"parentid=".$parentid." and modelid>0 order by listorder asc");
         $catlist=array();
         if(empty($row)){
                return $catlist;
         }
         $i=0;
         foreach ($row as $r){         
            $catid=$r["id"];
            $catsublist=listcategory($catid);
            $catlist[$catid]["catname"]=$r["catname"];
            $catlist[$catid]["catid"]=$catid;
            $catlist[$catid]["childlist"]=$catsublist;
         }
         
         return $catlist;
}
$catlist=listcategory(0);
$seledcat=array();
function showcatlist($catlist){
       global $selectlist,$seledcat;
       foreach($catlist as $key=>$row){
            if(!empty($row["childlist"])){
                 echo "<li><a>".$row["catname"]."</a><ul>\n";
                 
                    showcatlist($row["childlist"]);
                 
                  echo "</ul></li>\n";                
            }else{
            $chk="";
             if(in_array($row["catid"],$selectlist)){
              $chk='checked="true" chk="true"';
              $rd["id"]=$row["catid"];
              $rd["orgName"]=$row["catname"];
              
              
              $seledcat[]=$rd;
              
             }
              echo "<li><a tname=\"catid\" tvalue=\"{id:'".$row["catid"]."', orgName:'".$row["catname"]."'}\" ".$chk." >".$row["catname"]."</a></li>\n";   
            }
        
        
       }
}

?>